# in my /slowread/slowread/utils.py
# I will want to use this in a management command as well as a view
import requests
from wagtail.core.models import Page
from django.core.cache import cache

def request_all_pages():

    try:
        # 访问 / 主页
        print("访问 主页 http://localhost")
        requests.get("http://localhost")

        # 访问 /blog
        print("访问 博客列表页 http://localhost/blog")
        requests.get("http://localhost/blog")

        # 访问 /blog/*
        page = Page.objects.get(title="文章列表")
        blogpages = page.get_children().live().order_by('-first_published_at')
        for blogpage in blogpages:
            print("访问 文章 " + blogpage.full_url)
            requests.get(blogpage.full_url)

        # 访问 /wallpaper
        print("访问 博客列表页 http://localhost/wallpaper")
        requests.get("http://localhost/wallpaper")

    except Exception as e:
        print("Unexpected Error: {}".format(e))

# 默认情况下，Django的模板缓存使用名为“template.chache.”前缀键名
def clear_page_cache():
    # just clears all template fragment caches
    try:
        cache.delete_pattern("template.cache.*")
        print("Page Cache deleted...")
    except Exception as e:
        print("Unexpected Error: {}".format(e))